package com.kai.controller;

import com.alibaba.fastjson.JSONObject;
import com.kai.dto.FinanceWithdrawResponeDto;
import com.kai.dto.UserWithdrawResponeDto;
import com.kai.Util.ResultMsg;
import com.kai.Util.ResultStatusCode;
import com.kai.entity.*;
import com.kai.service.ExportService;
import com.kai.service.WalletService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

/**
 * Created by zhangkai on18/8/3
 *获取用户列表
 */
@Component
@RestController
@RequestMapping("/finance")
public class WalletFinanceController {

    private static Logger log = LoggerFactory.getLogger(WalletPalteListController.class);

    private final  static Integer NUM=1;

    private final  static Integer SIZE=10;
    @Autowired
    WalletService walletService;
    @Autowired
    ExportService exportService;


    /**
     * 财务报表管理
     * @param
     * @return
     */
    @PostMapping (value = "/walletFinanceList")
    @ResponseBody
    public Map<String, Object>  getFinanceListpage(@RequestBody JSONObject request){
        WalletFinance wf=new WalletFinance();

        if(request.get("address") !=null && !request.get("address").equals("")){
            wf.setToAddress(request.get("address").toString());
        }
        if(request.get("txid") !=null && !request.get("txid").equals("")){
            wf.setTxid(request.get("txid").toString());
        }
        if(request.get("accountType") !=null && !request.get("accountType").equals("")){
            wf.setCoinType(request.get("accountType").toString());
        }
        if(request.get("type") !=null && !request.get("type").equals("")){
            wf.setTxType(request.get("type").toString());
        }
        if(request.get("startTime") !=null && !request.get("startTime").equals("")){
            wf.setStartTime(request.get("startTime").toString());
        }
        if(request.get("endTime") !=null && !request.get("endTime").equals("")){
            wf.setEndTime(request.get("endTime").toString());
        }
        Integer num=NUM;
        Integer size=SIZE;
        if(request.get("pageNum") !=null){
            num= Integer.valueOf(request.get("pageNum").toString());
        }
        if(request.get("pageSize") !=null){
            size= Integer.valueOf(request.get("pageSize").toString());
        }
        return walletService.getFinanceListData(wf,num,size);
    }

    /**
     * 充值
     */
    @PostMapping (value = "/walletFianceRecharge")
    @ResponseBody
    public ResultMsg walletFianceRecharge(@RequestBody JSONObject request) throws ParseException {
        SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        WalletFinance wf=new WalletFinance();
        if(request.get("coinType") !=null && !request.get("coinType").equals("")){
            wf.setCoinType(request.get("coinType").toString());
        }
        if(request.get("startTime") !=null && !request.get("startTime").equals("")){
            Date date=format.parse(request.get("startTime").toString());
            wf.setStartTime(String.valueOf(date.getTime()/1000));
        }
        if(request.get("endTime") !=null && !request.get("endTime").equals("")){
            Date date=format.parse(request.get("endTime").toString());
            wf.setEndTime(String.valueOf(date.getTime()/1000));
        }
        if(request.get("dataCount") !=null && !request.get("dataCount").equals("")){
            wf.setDataNumber(Integer.parseInt(request.get("dataCount").toString()));
        }else{
            wf.setDataNumber(7);
        }
        return new ResultMsg(ResultStatusCode.OK.getCode(), ResultStatusCode.OK.getMsg(),walletService.walletImputationCount(wf));
    }

    /**
     * 提币
     */
    @PostMapping (value = "/walletMentionMoney")
    @ResponseBody
    public ResultMsg walletMentionMoney(@RequestBody JSONObject request){
        WalletFinance wf=new WalletFinance();
        return new ResultMsg(ResultStatusCode.OK.getCode(), ResultStatusCode.OK.getMsg(),walletService.walletMentionMoneyCount(wf));
    }



}